/**
 * 获取端口异常柱状图配置项
 */
function getPortAbnormalBarOption() {
  var option = {
    backgroundColor: '',
    tooltip: {
      trigger: 'axis',
      axisPointer: { // 坐标轴指示器，坐标轴触发有效
        type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
      }

    },
    grid: {
      left: '5',
      right: '40',
      bottom: '10',
      top: '30',
      containLabel: true
    },
    xAxis: [{
      name: '端口',
      nameTextStyle: {
        fontSize: 12,
      },
      data: ['80', '3306', '445', '25'],
      type: 'category',
      axisLine: {
        lineStyle: {
          color: 'black',
          width: 1, //这里是为了突出显示加上的
        }
      },
      axisTick: {
        alignWithLabel: true
      },

    }],
    yAxis: [{
      name: '事件数量',
      nameTextStyle: {
        fontSize: 12
      },
      type: 'value',
      axisLine: {
        lineStyle: {
          color: 'black',
          width: 1, //这里是为了突出显示加上的
        }
      },
      axisTick: {
        alignWithLabel: true
      },
      axisLabel: {
        formatter: '{value}'
      }
    }],
    series: [{
      barWidth: '40%',
      type: 'bar',
      data: [{
        value: 38,
        itemStyle: {
          normal: {
            color: '#003366'
          }
        }
      }, {
        value: 32,
        itemStyle: {
          normal: {
            color: '#006699'
          }
        }
      }, {
        value: 25,
        itemStyle: {
          normal: {
            color: '#4cabce'
          }
        }
      }, {
        value: 22,
        itemStyle: {
          normal: {
            color: '#dd545d'
          }
        }
      }],
      itemStyle: {
        normal: {
          //color: '#a08596'
          color: 'rgba(64,64,64,0.45)'
        }
      }
    }]
  };
  return option;
}

/**
 * 获取流量异常气泡图配置项
 */
function getStreamAbnormalBubbleOption() {

  var data = [
    ['2018-04-01 02:01:02', 15 * 60 + 37, 643],
    ['2018-04-01 12:00:00', 10 * 60 + 28, 579],
    ['2018-04-02 07:05:02', 30 * 60 + 16, 985],
    ['2018-04-02 15:02:02', 13 * 60 + 23, 713],
    ['2018-04-03 02:05:03', 62 * 60 + 15, 622]
  ];

  var option = {
    /*backgroundColor: new echarts.graphic.RadialGradient(0.3, 0.3, 0.8, [{
        offset: 0,
        color: '#f7f8fa'
    }, {
        offset: 1,
        color: '#cdd0d5'
    }]),*/
    title: {
      // text: '1990 与 2015 年各国家人均寿命与 GDP'
    },
    legend: {
      top: 0,
      right: 10,
      ///data: [{name:'防火墙',textStyle:{color:'#4cabce'}}, {name:'Web',textStyle:{color:'#f53d5f'}}]
      data: ['异常事件节点']
    },
    grid: {
      bottom: 85,
      top: 32,
      right: 65
    },
    tooltip: {
      trigger: 'item',
      formatter: function (param) {
        var durTime = param.data[1];
        var hour = Math.floor(durTime / 3600);
        var min = Math.floor((durTime - hour * 3600) / 60);
        var sec = (durTime - hour * 3600 - min * 60);
        if (hour < 10) hour = ("0" + hour);
        if (min < 10) min = ("0" + min);
        if (sec < 10) sec = ("0" + sec);

        return "流量异常<br/>发生时间：" + param.data[0] + "<br/>持续时间：" + hour + ":" + min + ":" + sec + "<br/>流量大小：" + param.data[2] + "MB";
      }
    },
    xAxis: {
      type: 'time',
      name: '发生时间',
      splitLine: {
        lineStyle: {
          type: 'dashed'
        }
      }
    },
    yAxis: {
      type: 'value',
      name: '持续时间',
      splitLine: {
        lineStyle: {
          type: 'dashed'
        }
      },
      axisLabel: {
        formatter: function (value) {

          var hour = Math.floor(value / 3600);
          var min = Math.floor((value - hour * 3600) / 60);
          var sec = (value - hour * 3600 - min * 60);
          //console.log(sec,min,hour);
          if (hour < 10) hour = ("0" + hour);
          if (min < 10) min = ("0" + min);
          if (sec < 10) sec = ("0" + sec);
          return "" + hour + ":" + min + ":" + sec;
        }
      },
      scale: true
    },
    dataZoom: [{
        type: 'slider',
        xAxisIndex: 0,
        start: 50,
        end: 100
      },
      {
        type: 'inside',
        xAxisIndex: 0,
        start: 50,
        end: 100
      }
    ],
    series: [{
      name: '异常事件节点',
      data: data,
      type: 'scatter',
      symbolSize: function (data) {
        return data[2] / 100 + 12;
      },
      label: {
        emphasis: {
          show: true,
          formatter: function (param) {
            return param.data[3];
          },
          position: 'top'
        }
      },
      itemStyle: {
        normal: {
          shadowBlur: 10,
          shadowColor: 'rgba(25, 100, 150, 0.5)',
          shadowOffsetY: 5,
          color: '#f53d5f'

        }
      }
    }]
  };
  return option;
}

/**
 * 获取访客异常树图配置项
 */
function getVisitorAbnormalTreeOption() {
  var option = {

    tooltip: {
      trigger: 'item',
      triggerOn: 'mousemove',
      formatter: `{b}`
    },

    series: [{
      type: 'tree',
      symbolSize: function (value) {
        return value + 10;
      },
      initialTreeDepth: 1,
      data: [{
        name: "受监测目标",
        value: 10,
        children: [{
            name: "杭州\n(共发起4次)",
            value: 4,
            children: [{
                name: "113.14.15.16\n(共发起1次)",
                value: 1
              },
              {
                name: "113.14.16.11\n(共发起1次)",
                value: 1
              },
              {
                name: "113.14.16.11\n(共发起1次)",
                value: 1
              },
              {
                name: "113.14.16.11\n(共发起1次)",
                value: 1
              },

            ]
          },
          {
            name: "上海\n(共发起2次)",
            value: 2,
            children: [{
                name: "113.14.15.16\n(共发起1次)",
                value: 1
              },
              {
                name: "113.14.16.11\n(共发起1次)",
                value: 1
              },

            ]
          },
          {
            name: "北京\n(共发起3次)",
            value: 3,
            children: [{
                name: "104.14.15.16\n(共发起1次)",
                value: 1
              },
              {
                name: "101.11.16.11\n(共发起1次)",
                value: 1
              },
              {
                name: "106.12.21.31\n(共发起1次)",
                value: 1
              },

            ]
          },
          {
            name: "乌鲁木齐\n(共发起1次)",
            value: 1,
            children: [{
                name: "110.17.15.32\n(共发起1次)",
                value: 1
              },

            ]
          }
        ]
      }],

      top: '1%',
      left: '120',
      bottom: '1%',
      right: '100',

      //symbolSize: 7,

      //orient: 'RL',

      label: {
        position: 'left',
        verticalAlign: 'middle',
        align: 'right'
      },

      leaves: {
        label: {
          position: 'right',
          verticalAlign: 'middle',
          align: 'left'
        }
      },

      expandAndCollapse: true,
      animationDuration: 550,
      animationDurationUpdate: 750
    }]
  }
  return option;
}

/**
 * 获取访客异常地图配置项
 */
function getVisitorAbnormalMapOption(){
  var option = {
    backgroundColor: '',
    title: {
        left: 'center',
        textStyle: {
            color: '#fff'
        }
    },
    tooltip: {
        trigger: 'item'
    },
    geo: {
        map: 'china',
        label: {
            emphasis: {
                show: false
            }
        },
        roam: true,
        itemStyle: {
            normal: {
                areaColor: '#fcfcfc',
                borderColor: '#006699',
                borderWidth: 1
            },
            emphasis: {
                areaColor: '#4ca1c2'
            }
        }
    },
    series: [

        {
            name: "访客源所在城市",
            type: 'effectScatter',
            coordinateSystem: 'geo',
            zlevel: 2,
            symbol: "emptyCircle",
            symbolSize: function (val) {
                return 10 + val[2] / 10;
            },
            rippleEffect: {
                period: 4,
                scale: 5,
                brushType: 'stroke'
            },
            label: {
                show: false
            },
            itemStyle: {
                normal: {
                    color: "red",
                    opacity: 0.5
                }
            },
            tooltip: {
                formatter: function (param) {
                    return `${param.value[3]}<br/>共发起${param.value[2]}次攻击`;

                }
            },
            data: [
                [119.5313, 29.8773, 66, "杭州"]

            ],
        }
    ]
};
return option;
}

/**
 * 获取异常事件饼图配置项
 */
function getAbnormalEventsPieOption() {
  var option = {
    title: {},
    color: ['#003366', '#006699', '#4cabce', '#f53d5f'],
    tooltip: {
      trigger: 'item'
    },
    calculable: true,
    series: [{
      name: '面积模式',
      type: 'pie',
      radius: [40, 90],
      center: ['50%', '50%'],
      roseType: 'area',
      tooltip: {
        show: true,
        formatter: '{b} <br/>告警次数: {c} 次(占比{d}%)'
      },
      data: [{
          value: 10,
          name: 'IP访问异常'
        },
        {
          value: 5,
          name: '端口访问异常'
        },
        {
          value: 15,
          name: '访问流量异常'
        },
        {
          value: 25,
          name: '访客访问异常'
        },
      ]
      /* .sort(function (a, b) {
                        return a.value - b.value;
                      }), */
    }]
  };

  var option2 = {
    backgroundColor: '',

    tooltip: {
      trigger: 'item',
      formatter: "{b} <br/>总计事件数：{c}次 ({d}%)"
    },

    visualMap: {
      show: false,
      min: 80,
      max: 600,
      inRange: {
        colorLightness: [0, 1]
      }
    },
    series: [{
      name: '异常事件告警',
      type: 'pie',
      radius: '55%',
      center: ['50%', '50%'],
      data: [{
          value: 335,
          name: 'IP访问异常'
        },
        {
          value: 310,
          name: '端口访问异常'
        },
        {
          value: 274,
          name: '访问流量异常'
        },
        {
          value: 235,
          name: '访客访问异常'
        },
      ].sort(function (a, b) {
        return a.value - b.value;
      }),
      roseType: 'radius',
      label: {
        normal: {
          textStyle: {
            color: 'rgba(0, 0, 0, 0.8)'
          }
        }
      },
      labelLine: {
        normal: {
          lineStyle: {
            color: 'rgba(0, 0, 0, 0.8)'
          },
          smooth: 0.2,
          length: 10,
          length2: 20
        }
      },
      itemStyle: {
        normal: {
          color: '#c23531',
          shadowBlur: 20,
          shadowColor: 'rgba(0, 0, 0, 0.5)'
        }
      },

      animationType: 'scale',
      animationEasing: 'elasticOut',
      animationDelay: function (idx) {
        return Math.random() * 200;
      }
    }]
  };
  return option;
}